import router from '@/router'
import { useUserStore } from './store/user'
import { haveData } from './utils/is-have-data'

router.beforeEach((to, from) => {
  const userStore = useUserStore()
  if (to.name !== 'login') {
    if (haveData(userStore.token)) {
      userStore.profile()
    }
  }
  if (!to.meta.user) {
    return true
  }

  if (userStore.token) {
    return true
  }

  return '/'
})
